package system.org.databaseConnect;
import java.sql.*;

import system.org.entity.Employee;


public class DB_connect {
	
	public Connection DBconnect(){
		String url="jdbc:mysql://localhost:3306/equestrianbetsystemdb"; // Port 3306
		 String userName="root";
		 String password="";
		 Connection connection = null;
		 
		 System.out.println("-------- MySQL JDBC Connection Testing ------------");
		 
			try {
				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException e) {
				System.out.println("NotFound MySQL JDBC Driver.");
				e.printStackTrace();
				return null;
			}
		 
			System.out.println("MySQL JDBC Driver Registered!");
		 
			try {
				connection = DriverManager.getConnection(url,userName,password);
		 
			} catch (SQLException e) {
				System.out.println("Connection Failed! Check output console");
				e.printStackTrace();
				return null;
			}
		 
			if (connection != null) {
				System.out.println("Connection successfull!.");
				return connection;
			} else {
				System.out.println("Connection failed!");
			}
		 return null;
	}
	
	 public static void main(String[] args) {
		 ProcessDB process = new ProcessDB();
		 Employee emp = new Employee(System.currentTimeMillis()+"",
				 "hai", "nguyen", new Date(System.currentTimeMillis()), "123 abc", "09011111111", 
				 "hai@gmail.com", "haiviet", "123456789", "");
		 int res=0;
		try {
			res = process.insertNewEmployee(emp);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
		 System.out.println(res);
	    }  
}
